package com.sai.jsai.module.auth.controller;

import com.sai.jsai.common.base.vo.RestResult;
import com.sai.jsai.module.auth.domain.vo.LoginReqVO;
import com.sai.jsai.module.auth.domain.vo.LoginRespVO;
import com.sai.jsai.module.auth.service.AuthService;
import com.sai.jsai.module.system.api.dto.SysUserRolePermissionDTO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

/**
 * @author jisai
 * @version 0.0.1
 * @Description TODO
 * @createTime 2024/09/21
 */
@Tag(name = "登录认证 - 认证")
@RestController
@RequestMapping("/auth")
public class AuthController {
    @Resource
    AuthService authService;

    @Operation(summary = "用户名密码登录")
    @PostMapping("/login")
    public RestResult<LoginRespVO> login(@RequestBody LoginReqVO loginReqVO) {
        return RestResult.success(authService.login(loginReqVO));
    }

    @Operation(summary = "获取登录用户的信息")
    @GetMapping("/login-user-info")
    public RestResult<SysUserRolePermissionDTO> getLoginUserInfo() {
        return RestResult.success(authService.getSysUserRolePermissionBySessionUser());
    }

    @Operation(summary = "登出")
    @PostMapping("/logout")
    public RestResult logout() {
        authService.logout();
        return RestResult.success();
    }

}
